package com.jueling.culture.controller;

import com.jueling.culture.core.Result;
import com.jueling.culture.core.ResultGenerator;
import com.jueling.culture.dto.req.QueryVO;
import com.jueling.culture.service.ContributionAwardService;
import com.jueling.culture.util.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
* @describe 贡献奖
* @author linp
* @date 2022/04/11
*/
@RestController
public class ContributionAwardController {
    @Autowired
    private ContributionAwardService contributionAwardService;

    /**
     * 贡献奖领取
     * @param gxjId
     * @return
     */
    @PutMapping("/api/contribution/award/{gxjId}")
    public Result update(@PathVariable String gxjId) {
        contributionAwardService.updateContributionAward(gxjId);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 贡献奖结算
     * @return
     */
    @PutMapping("/api/close/contribution/award")
    public Result close() {
        contributionAwardService.closeContributionAward();
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/api/contribution/award")
    public Result list(@ModelAttribute QueryVO queryVO) {
        return ResultGenerator.genSuccessResult(contributionAwardService.getContributionAwardList(queryVO));
    }

    /**
     * 导出
     * @return
     */
    @GetMapping("/api/contribution/down/load/data")
    public void downloadData(@ModelAttribute QueryVO queryVO, HttpServletResponse response) {
        List<List<Object>> allAgentData = contributionAwardService.getAllContributionAwardList(queryVO);
        List<String> channels = new ArrayList<>();
        channels.add("代理名称");
        channels.add("代理编号");
        channels.add("手机号");
        channels.add("注册日期");
        channels.add("本期贡献奖(本人)");
        channels.add("本期贡献奖(全部)");
        channels.add("是否已领取");
        channels.add("结算状态");
        channels.add("是否虚拟用户");
        channels.add("实际用户");
        channels.add("代理级别");
        channels.add("状态");
        channels.add("推荐人");
        channels.add("新推荐人");
        channels.add("开户行名称");
        channels.add("开户名");
        channels.add("银行卡号");
        channels.add("收获地址");
        channels.add("结算时间");
        ExcelUtil.exportExcel(allAgentData,channels, response ,"贡献奖明细");
    }


}
